#pragma once

class IndexOutOfRangeException { };

template<typename T>
class SimpleList
{
public:
	SimpleList() : m_count(0), m_items(nullptr)
	{
		m_items = (T *) malloc(0);
	}

	void Add(T &item)
	{
		m_items = (T *) realloc(m_items, (++m_count) * (sizeof(T)));
		m_items[m_count - 1] = item;
	}

	void Clear()
	{
		internal_clear();
		m_items = (T *) malloc(0);
	}

	T &operator [](int index)
	{
		if (index >= m_count)
		{
			throw IndexOutOfRangeException();
		}
		return m_items[index];
	}

	__declspec(property(get = get_Count)) int Count;
	int get_Count() { return m_count; }

	~SimpleList()
	{
		internal_clear();
	}

private:
	void internal_clear()
	{
		free(m_items);
		m_count = 0;
		m_items = nullptr;
	}

	int	 m_count;
	T	*m_items;
};
